package zhihuilan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import zhihuilan.dto.MyOrderDto;
import zhihuilan.entity.MyPcd;
import zhihuilan.entity.MyStaff;
import zhihuilan.mapper.MyPcdMapper;
import zhihuilan.mapper.MyStaffMapper;
import zhihuilan.service.MyPcdService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class MyPcdServiceImpl extends ServiceImpl<MyPcdMapper, MyPcd> implements MyPcdService {


    @Override
    public List<MyPcd> selectHotList(String keyword) {
//        if (ObjectUtils.isEmpty(keyword)) {
//            return null;
//        }
        QueryWrapper<MyPcd> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(keyword))
            queryWrapper.like("name", keyword);
        queryWrapper.eq("ishot", 1);
        queryWrapper.eq("status", 1);
        queryWrapper.eq("level", 2);
        queryWrapper.orderByAsc("sort");
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<String> selectEnList(String keyword) {
//        if (ObjectUtils.isEmpty(keyword)) {
//            return null;
//        }
        QueryWrapper<MyPcd> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("en");
        if (!ObjectUtils.isEmpty(keyword))
            queryWrapper.like("name", keyword);
        queryWrapper.eq("status", 1);
        queryWrapper.eq("level", 2);
        queryWrapper.orderByAsc("en");
        queryWrapper.groupBy("en");
        List<MyPcd> list = baseMapper.selectList(queryWrapper);
        List<String> convertList = list.stream().map(po -> {
            String en = po.getEn();
            return en;
        }).collect(Collectors.toList());
        return convertList;
    }

    @Override
    public List<Map<String, Object>> selectCityList(String keyword, List<String> enList) {

//        if (ObjectUtils.isEmpty(keyword)) {
//            return null;
//        }
        List<Map<String, Object>> convertList = enList.stream().map(po -> {
            Map<String, Object> map = new HashMap<>();
            map.put("name", po);
            QueryWrapper<MyPcd> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("status", 1);
            queryWrapper1.eq("level", 2);
            queryWrapper1.eq("en", po);
            if (!ObjectUtils.isEmpty(keyword))
                queryWrapper1.like("name", keyword);
            queryWrapper1.orderByAsc("sort");
            List<MyPcd> selectList = baseMapper.selectList(queryWrapper1);
            map.put("list", selectList);
            return map;
        }).collect(Collectors.toList());
        return convertList;
    }

    @Override
    public MyPcd selectMyPcdById(Integer id) {
        return this.baseMapper.selectById(id);
    }

    @Override
    public MyPcd selectMyPcdByCode(Integer code) {
        QueryWrapper<MyPcd> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("code", code);
        return this.baseMapper.selectOne(queryWrapper);
    }

}
